Partner – Microsoft – NPI EA (cat = Baeldung)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Microsoft – NPI EA (cat= Spring Boot)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, you can get started over on the documentation page.

And, you can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – MongoDB – NPI EA (tag=MongoDB)
announcement - icon

Traditional keyword-based search methods rely on exact word matches, often leading to irrelevant results depending on the user's phrasing.

By comparison, using a vector store allows us to represent the data as vector embeddings, based on meaningful relationships. We can then compare the meaning of the user’s query to the stored content, and retrieve more relevant, context-aware results.

Explore how to build an intelligent chatbot using MongoDB Atlas, Langchain4j and Spring Boot:

>> Building an AI Chatbot in Java With Langchain4j and MongoDB Atlas

Partner – LambdaTest – NPI EA (cat=Testing)
announcement - icon

Accessibility testing is a crucial aspect to ensure that your application is usable for everyone and meets accessibility standards that are required in many countries.

By automating these tests, teams can quickly detect issues related to screen reader compatibility, keyboard navigation, color contrast, and other aspects that could pose a barrier to using the software effectively for people with disabilities.

Learn how to automate accessibility testing with Selenium and the LambdaTest cloud-based testing platform that lets developers and testers perform accessibility automation on over 3000+ real environments:

Automated Accessibility Testing With Selenium

eBook – Maven – NPI (cat=Maven)
announcement - icon

Get up to speed with the core of Maven quickly, and then go beyond the foundations into the more powerful functionality of the build tool, such as profiles, scopes, multi-module projects and quite a bit more:

>> Download the core Maven eBook

1. The Problem and the Options

Maven is a very versatile tool and its available public repositories are second to none. However there will always be an artifact that is either not hosted anywhere, or the repository where it is hosted is risky to depend on, as it may not be up when you need it.

When that happens, there are a few choices:

  • bite the bullet and install a full fledged repository management solution such as Nexus
  • try to get the artifact uploaded into one of more reputable public repositories
  • install the artifact locally using a maven plugin

Nexus is of course the more mature solution, but it’s also the more complex. Provisioning an instance to run Nexus, setting up Nexus itself, configuring and maintaining it may be overkill for such a simple problem as using a single jar. If this scenario – hosting custom artifacts – is a common one however, a repository manager makes a lot of sense.

Getting the artifact uploaded into a public repository or in Maven central directly is also a good solution, but usually a lengthy one. In addition, the library may not be Maven enabled at all, which makes the process that much more difficult, so it’s not a realistic solution to being able to use the artifact NOW.

That leaves the third option – adding the artifact in source control and using a maven plugin – in this case, the maven-install-plugin to install it locally before the build process needs it. This is by far the easiest and most reliable option available.

2. Install Local Jar With the maven-install-plugin

Let’s start with the full configuration necessary to install the artifact into our local repository:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-install-plugin</artifactId>
   <version>3.1.2</version>
   <configuration>
      <groupId>org.somegroup</groupId>
      <artifactId>someartifact</artifactId>
      <version>1.0</version>
      <packaging>jar</packaging>
      <file>${basedir}/dependencies/someartifact-1.0.jar</file>
      <generatePom>true</generatePom>
   </configuration>
   <executions>
      <execution>
         <id>install-jar-lib</id>
         <goals>
            <goal>install-file</goal>
         </goals>
         <phase>validate</phase>
      </execution>
   </executions>
</plugin>

Now, let’s break down and analyze the details of this configuration.

2.1. The Artifact Information

The Artifact Information is defined as part of the <configuration> element. The actual syntax is very similar to declaring the dependency – a groupId, artifactId and version elements.

Next part of the configuration requires defining the packaging of the artifact – this is specified as jar.

Next, we need to provide the location of the actual jar file to be installed – this can be an absolute file path or it can be relative, using the properties available in Maven. In this case, the ${basedir} property represents the root of the project, namely the location where the pom.xml file exists. This means that the someartifact-1.0.jar file needs to be placed in a /dependencies/ directory under the root.

Finally, there are several other optional details that can be configured as well.

2.2. The Execution

The execution of the install-file goal is bound to the validate phase from the standard Maven build lifecycle. As such, before attempting to compile – you will need to run the validation phase explicitly:

mvn validate

After this step, the standard compilation will work:

mvn clean install

Once the compile phase does execute, our someartifact-1.0.jar is correctly installed in our local repository, just as any other artifact that may have been retrieved from Maven central itself.

2.3. Generating a POM vs Supplying the POM

The question of whether we need to supply a pom.xml file for the artifact or not depends on mainly on the runtime dependencies of the artifact itself. Simply put, if the artifact has runtime dependencies on other jars, these jars will need to be present on the classpath at runtime as well. With a simple artifact that should not be a problem, as it will likely have no dependencies at runtime (a leaf in the dependency graph).

The generatePom option in the install-file goal should suffice for these kinds of artifacts:

<generatePom>true</generatePom>

However, if the artifact is more complex and does have non-trivial dependencies, then, if these dependencies are not already in the classpath, they must be added. One way to do that is by defining these new dependencies manually in the pom file of the project. A better solution is to provide a custom pom.xml file along with the installed artifact:

<generatePom>false</generatePom>
<pomFile>${basedir}/dependencies/someartifact-1.0.pom</pomFile>

This will allow Maven to resolve all dependencies of the artifact defined in this custom pom.xml, without having to define them manually in the main pom file of the project.

3. Using Maven Commands

In this section, let’s learn how to use Maven commands to install a local jar. We’ll discuss the installation and usage of the jar in a simple project.

3.1. Setup JAR

First, let’s start by looking at the file structure for our library project using the exa command:

$ exa --tree .
.
├── com
│  └── baeldung
│     └── HelloWorld.java
└── manifest.txt

We can note that the library project contains a single HelloWorld.java file and a manifest.txt file.

Now, let’s see the hello() method in the HelloWorld class:

$ cat com/baeldung/HelloWorld.java
package com.baeldung;

public class HelloWorld {

    public static void hello() {
        System.out.println("Hello, world!");
    }

    public static void main() {
        hello();
    }
}

Next, let’s compile the HelloWorld.java file to generate the HelloWorld class and update the manifest.txt file:

$ javac com/baeldung/HelloWorld.java
$ cat manifest.txt
Main-Class: com.baeldung.HelloWorld

Lastly, we’re ready to package our library file in the HelloWorld.jar file:

$ jar cvfm HelloWorld.jar manifest.txt com/baeldung/HelloWorld.class
added manifest
adding: com/baeldung/HelloWorld.class(in = 479) (out= 320)(deflated 33%)

3.2. Install HelloWorld.jar

Now that we’ve got the jar file, we’ll use the mvn install:install-file command to install it in the local repository:

$ mvn install:install-file \
-Dfile=HelloWorld.jar \
-DgroupId=com.baeldung \
-DartifactId=hello-world \
-Dversion=1.0 \
-Dpackaging=jar

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- install:3.1.0:install-file (default-cli) @ standalone-pom ---
[INFO] pom.xml not found in HelloWorld.jar
[INFO] Installing /Users/tavasthi/baeldung/bael-2601/my-lib/HelloWorld.jar to /Users/tavasthi/.m2/repository/com/baeldung/hello-world/1.0/hello-world-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.160 s
[INFO] Finished at: 2023-06-14T17:38:18+05:30
[INFO] ------------------------------------------------------------------------

We must note that we didn’t have a pom.xml for our library project, so we’ve provided the groupId, artifactId, version, and packaging information using the -D option.

Further, let’s use the exa command to verify that the jar file is installed in the local .m2 repository:

$ exa --tree ~/.m2/repository/com/baeldung/hello-world
/Users/tavasthi/.m2/repository/com/baeldung/hello-world
├── 1.0
│  ├── _remote.repositories
│  ├── hello-world-1.0.jar
│  └── hello-world-1.0.pom
└── maven-metadata-local.xml

Great! We’ve got this one right. Additionally, we can also see that the command generated a pom.xml file as well.

3.3. Using HelloWorld.jar in a Project

To use the project, let’s create the my-project Maven project using the mvn command:

$ mvn archetype:generate \
-DgroupId=com.baeldung \
-DartifactId=my-project \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false

Now, let’s use the exa command to see the directory structure of our project:

$ exa --tree my-project
my-project
├── pom.xml
└── src
   ├── main
   │  └── java
   │     └── com
   │        └── baeldung
   │           └── App.java
   └── test
      └── java
         └── com
            └── baeldung
               └── AppTest.java

Next, let’s add the hello-world dependency in the project’s pom.xml file:

<dependency>
    <groupId>com.baeldung</groupId>
    <artifactId>hello-world</artifactId>
    <version>1.0</version>
</dependency>

Moving on, let’s call the hello() method from our library in our target project:

public class App 
{
    public static void main( String[] args )
    {
        com.baeldung.HelloWorld.hello();
    }
}

Finally, let’s see this in action by running our target project:

$ mvn clean install && mvn exec:java -Dexec.mainClass="com.baeldung.App"     

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.baeldung:my-project >-----------------------
[INFO] Building my-project 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec:3.1.0:java (default-cli) @ my-project ---
Hello, world!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.232 s
[INFO] Finished at: 2023-06-14T17:42:31+05:30
[INFO] ------------------------------------------------------------------------

Fantastic! We can see that the hello() method was executed successfully.

4. Conclusion

This article goes over how to use a jar which is not hosted anywhere within a Maven project by installing it locally with the maven-install-plugin. Additionally, we used the maven commands to setup and install a local jar, followed by using it in a target project.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

Partner – Microsoft – NPI EA (cat = Baeldung)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Microsoft – NPI EA (cat = Spring Boot)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Partner – MongoDB – NPI EA (tag=MongoDB)
announcement - icon

Traditional keyword-based search methods rely on exact word matches, often leading to irrelevant results depending on the user's phrasing.

By comparison, using a vector store allows us to represent the data as vector embeddings, based on meaningful relationships. We can then compare the meaning of the user’s query to the stored content, and retrieve more relevant, context-aware results.

Explore how to build an intelligent chatbot using MongoDB Atlas, Langchain4j and Spring Boot:

>> Building an AI Chatbot in Java With Langchain4j and MongoDB Atlas

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)